package com.zking.test;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

import java.util.UUID;

public class Shiro {

    public static void main(String[] args) {
        String hashAlgorithmName = "SHA1";
        Object credentials = "123456";
        String saltStr = UUID.randomUUID().toString().replaceAll("\\-","");
        System.out.println(saltStr);
        //用户名作为盐值，用户名是唯一，配上密码就是唯一的。
        Object salt = ByteSource.Util.bytes(saltStr);
        //Object salt = null;
        int hashIterations = 256;
        //SimpleHash：shiro专门加密
        //hashAlgorithmName:加密的类型，SHA1加密，MD5加密
        //credentials:加密的密码
        //hashIterations:加密的次数
        //salt:盐值
        //MD5
        //一次加密，没有加入盐值：
        //e10adc3949ba59abbe56e057f20f883e
        //999次加密，没有加入盐值
        //74b1433794e21f7d0afabdafe5efd3f0
        //999次加密，加入盐值
        //c845f7697db6aabd302ca11247016fe0

        //加了admin盐值的
        //038bdaf98f2037b31f1e75b5b4c9b26e
        Object result = new SimpleHash(hashAlgorithmName, credentials, salt, hashIterations);
        System.out.println(result);
    }

}
